package 富婆梦.第一阶段.第四周.作业;


import java.util.ArrayList;
import java.util.Scanner;

/**
 * @ProjectName: java-learning
 * @Package: 富婆梦.第一阶段.第四周.作业
 * @ClassName: TestVehicle
 * @Author: hemengjin
 * @Description: 测试交通工具的类
 * @Date:2021/8/1 18:55
 * @Version: 1.0
 */
public class TestVehicle {
    public static void main(String[] args) {
        Vehicle car = new Car();
        Vehicle bus = new Bus();
        Vehicle bike = new Bike();
        Vehicle motor = new Motor();
        Vehicle highSpeedrail = new HighSpeedrail();
        Vehicle train = new Train();
        Vehicle ship = new Ship();
        Vehicle aircraft =new Aircraft();
        ArrayList<Vehicle> list = new ArrayList<>();
        list.add(car);
        list.add(bus);
        list.add(bike);
        list.add(motor);
        list.add(highSpeedrail);
        list.add(train);
        list.add(ship);
        list.add(aircraft);

        System.out.println(ship.getClass());
        System.out.println("你可以选择查看下面几个类的继承树，请输入你的选择(输入选项前的编码即可)：");
        for (int i=0;i<list.size();i++) {
            System.out.println((i+1)+"."+list.get(i).getClass());
        }
        Vehicle vehicle;
        while (true){
            int userNum = new TestVehicle().select_num();
            if (userNum>list.size()||userNum<=0){
                System.out.println("您输入的选项不正确！！！请重新输入");
            }
            for (int i=0;i<list.size();i++) {
                if ((userNum-1)==i){
                    vehicle = list.get(i);
                    Class c = vehicle.getClass();
                    System.out.println("这是 "+c+" 类，他的继承树如下：");
                    Class sc = c.getSuperclass();
                    System.out.print(sc);
                    while (sc!=null){
                        sc = sc.getSuperclass();
                        if (sc!=null){
                            System.out.print(" --> "+sc);
                        }
                    }
                    break;
                }
            }
        }
    }
/**
 *@Method select_num
 *@Author 18279
 *@Version 1.0
 *@Description 用于接收用户输入的选项
 No such property: code for class: Script1
 */
    public int select_num(){
        Scanner sc = new Scanner(System.in);
        if (sc.hasNextInt()){
            return sc.nextInt();
        }else {
            System.out.println("请输入数字哦！！！");
        }
        return -1;
    }
}
